package dao;

import entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/4/26 11:22
 * Version:1.0-SNAPSHOT
 * Description:
 */
public interface UserMapper {

//    @Insert(value = "insert into t_user (username,password,phone,address) values(#{username},#{password},#{phone},#{address})")
    @Insert("insert into t_user (username,password,phone,address) values(#{username},#{password},#{phone},#{address})")
    public void insertUser(User user);

    public void deleteById(Integer id);

    public void updateUser(User user);

    public User selectById(Integer id);

    // 强行一致,别名
//    @Select("select user_id 'id',user_username 'username',user_password 'password',user_phone 'phone',user_address 'address' from t_user2 where user_id = #{id}")
    // 手动映射
    @Select("select * from t_user2 where user_id = #{id}")
    // @Results相当于ResultMap标签的配置
    // 通过value属性指定其值
    // 其值是一个数组类型
    // 数组中的每一个元素相当于ResultMap标签中的一个子标签
    // 每一个元素使用注解@Result表示,相当于id标签与result标签
    // 在@Result注解中,存在id属性,其值是一个布尔类型
    // 其值为true则表示主键配置,其值为false则表示普通字段
    // 即:值为true相当于id标签,值为false相当于result标签
    @Results(value = {
            @Result(id = true,property = "id", column = "user_id"),
            @Result(property = "username",column = "user_username"),
            @Result(property = "password",column = "user_password"),
            @Result(property = "phone",column = "user_phone"),
            @Result(property = "address",column = "user_address")
    })
    public User selectById2(Integer id);

    public List<User> selectAll();

}
